//
//  STProductDeitailLabelView.m
//  CuiBoStore
//
//  Created by 崔博 on 16/12/8.
//  Copyright © 2016年 崔博. All rights reserved.
//

#import "STProductDeitailLabelView.h"

@interface STProductDeitailLabelView ()
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *priceLabel;
@property (nonatomic, strong) UILabel *lineLabel;
@property (nonatomic, strong) UILabel *contentLabel;
@property (nonatomic, strong) UIButton *nextBtn;
@property (nonatomic, strong) UILabel *shopName;
@property (nonatomic, strong) UIImageView *shopIcon;
@property (nonatomic, strong) UIImageView *contryImageView;
@property (nonatomic, strong) UILabel *countryName;
@property (nonatomic, strong) UIImageView *nextImageView;
@property (nonatomic, strong) UIImageView *arrowImageView;
@property (nonatomic, strong) UIView *backView;
@property (nonatomic, strong) UILabel *toastLabel;
@property (nonatomic, strong) UILabel *picLabl;
@end
@implementation STProductDeitailLabelView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self == [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
        [self addSubviews];
    }
    return self;
}
#pragma mark - mothed
- (void)addSubviews
{
    [self addSubview:self.titleLabel];
    [self addSubview:self.priceLabel];
    [self addSubview:self.lineLabel];
    [self addSubview:self.contentLabel];
    [self addSubview:self.backView];
    [self addSubview:self.nextBtn];
    [self addSubview:self.shopName];
    [self addSubview:self.shopIcon];
    [self addSubview:self.contryImageView];
    [self addSubview:self.nextImageView];
    [self addSubview:self.arrowImageView];
    [self addSubview:self.toastLabel];
    [self addSubview:self.picLabl];
    [self layoutSubview];
}
- (void)layoutSubview
{
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self);
        make.right.equalTo(@(-20));
        make.left.equalTo(@(20));
        make.height.equalTo(@30);
    }];
    
    [_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.left.equalTo(@0);
        MASONRY(top, _titleLabel.mas_bottom, 25);
        make.height.equalTo(@20);
    }];
    
    [_lineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-15));
        make.left.equalTo(@15);
        MASONRY(top, _priceLabel.mas_bottom, 25);
        make.height.equalTo(@1);
    }];
    
    [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        MASONRY(top, _lineLabel.mas_bottom, 20);
        make.left.equalTo(@15);
        make.right.mas_equalTo(-15);
    }];
    
    [_backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
        make.height.equalTo(@100);
        MASONRY(top, _contentLabel.mas_bottom, 18);
    }];
    
    [_nextBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        MASONRYINSERT(_backView, 10, 0, 10, 0);
    }];
    
    [_shopIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        MASONRY(left, _nextBtn.mas_left, 15);
        make.size.mas_equalTo(CGSizeMake(50, 50));
        make.centerY.equalTo(_nextBtn);
    }];
    
    [_shopName mas_makeConstraints:^(MASConstraintMaker *make) {
        MASONRY(top, _shopIcon.mas_top, 5);
        MASONRY(left, _shopIcon.mas_right, 15);
        make.height.equalTo(@12);
    }];
    
    [_contryImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(18, 13));
        MASONRY(left, _shopIcon.mas_right, 15);
        MASONRY(bottom, _shopIcon.mas_bottom, -5);
    }];
    
    [_countryName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_contryImageView);
        make.size.mas_equalTo(CGSizeMake(70, 15));
        MASONRY(left, _contryImageView.mas_right, 5);
    }];
    
    [_arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(10, 15));
        make.centerY.equalTo(_shopIcon);
        make.right.equalTo(@(-15));
    }];
    
    [_toastLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_arrowImageView);
        make.height.equalTo(@14);
        make.width.equalTo(@90);
        MASONRY(right, _arrowImageView.mas_left, -5);
    }];
    
    [_picLabl mas_makeConstraints:^(MASConstraintMaker *make) {
        MASONRY(top, _backView.mas_bottom, 18);
        make.left.equalTo(@16);
        make.height.equalTo(@18);
    }];
}
#pragma mark - set 
- (void)setTitleModel:(STProduceTitleDataModel *)titleModel
{
    _titleModel = titleModel;
    _titleLabel.text = titleModel.Abbreviation;
    CGFloat height = [titleModel.Abbreviation heightForFont:[UIFont systemFontOfSize:15] width:SCREEN_WIDTH - 60];
    [_titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(height));
    }];
    
    _priceLabel.text = [NSString stringWithFormat:@"%@%@(%@)",titleModel.Price,titleModel.OriginalPrice,titleModel.Discount];
    NSArray *colors = @[[UIColor redColor],[UIColor lightGrayColor],[UIColor blackColor]];
    NSArray *texts = @[titleModel.Price,titleModel.OriginalPrice,titleModel.Discount];
    NSArray *fontArray = @[[UIFont systemFontOfSize:13],[UIFont systemFontOfSize:15],[UIFont systemFontOfSize:17]];
    [_priceLabel wl_changgeColors:colors texts:texts fonts:fontArray];
    
    _contentLabel.text = titleModel.GoodsIntro;
    CGFloat contentH = [titleModel.GoodsIntro heightForFont:[UIFont systemFontOfSize:13] width:SCREEN_WIDTH - 30];
    
    [_priceLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(contentH));
    }];
    
    [_shopIcon downloadImage:titleModel.ShopImage placeholder:nil];
    _shopName.text = titleModel.BrandCNName;
    _countryName.text = titleModel.CountryName;
    
    if (_heghtBlock) {
        _heghtBlock(230 + height + contentH + 46);
    }
}
#pragma mark - lazy
- (UILabel *)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [STUIKitTools lableFont:15 textColor:[UIColor blackColor]];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.numberOfLines = 0;
    }
    return _titleLabel;
}
- (UILabel *)priceLabel
{
    if (!_priceLabel) {
        _priceLabel = [[UILabel alloc] init];
        _priceLabel.textAlignment = NSTextAlignmentCenter;
        _priceLabel.text = @"￥128";
    }
    return _priceLabel;
}
- (UILabel *)lineLabel
{
    if (!_lineLabel) {
        _lineLabel = [[UILabel alloc] init];
        _lineLabel.backgroundColor = RGB(242, 242, 242);
    }
    return _lineLabel;
}
- (UILabel *)contentLabel
{
    if (!_contentLabel) {
        _contentLabel = [STUIKitTools lableFont:13 textColor:RGB(83, 83, 83)];
        _contentLabel.numberOfLines = 0;
    }
    return _contentLabel;
}
- (UIButton *)nextBtn
{
    if (!_nextBtn) {
        _nextBtn = [STUIKitTools buttonTitle:@"" font:14 action:@selector(jump) titleColor:[UIColor blackColor] target:self];
        _nextBtn.backgroundColor = [UIColor whiteColor];
    }
    return _nextBtn;
}
- (UILabel *)shopName
{
    if (!_shopName) {
        _shopName = [STUIKitTools labelFont:12];
        _shopName.text = @"万宝路";
    }
    return _shopName;
}
- (UIImageView *)shopIcon
{
    if (!_shopIcon) {
        _shopIcon = [[UIImageView alloc] init];
    }
    return _shopIcon;
}
- (UILabel *)countryName
{
    if (!_countryName) {
        _countryName = [STUIKitTools labelFont:12];
        _countryName.text = @"美国";
    }
    return _contentLabel;
}
- (UIImageView *)contryImageView
{
    if (!_contryImageView) {
        _contryImageView = [[UIImageView alloc] init];
    }
    return _contryImageView;
}
- (UIImageView *)arrowImageView
{
    if (!_arrowImageView) {
        _arrowImageView = [STUIKitTools imageView:@"详情界面返回按钮"];
    }
    return _arrowImageView;
}
- (UIView *)backView
{
    if (!_backView) {
        _backView = [[UIView alloc] init];
        _backView.backgroundColor = BACKGROUND_COLOR;
    }
    return _backView;
}
- (UILabel *)toastLabel{
    if (!_toastLabel) {
        _toastLabel = [STUIKitTools lableFont:10 textColor:[UIColor lightGrayColor] text:@"(查看同品牌商品)"];
    }
    return _toastLabel;
}
- (UILabel *)picLabl
{
    if (!_picLabl) {
        _picLabl = [STUIKitTools lableFont:17 textColor:[UIColor blackColor] text:@"图文详情"];
    }
    return _picLabl;
}
@end
